package com.recharge.controller;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.entity.Customer;
import com.entity.Recharge;
import com.recharge.entity.JsonRecharge;
import com.recharge.entity.JsonRechargeCustomer;
import com.recharge.srevice.RefundService;
import com.utils.JsonResult;

/**
 * @Title: RefundController.java
 * @Package com.recharge.controller
 * @author 孙梦楠
 * @date 2017年8月28日 下午7:48:48
 * @version V1.0.0
 */
@RestController
@RequestMapping(value = "/refund")
public class RefundController {

	@Autowired
	private RefundService refundservice;

	// 列表
	@RequestMapping(value = "/list_refund_customer_total", method = RequestMethod.POST)
	public JsonResult<List<JsonRechargeCustomer>> list_refund_customer_total(
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
			@CookieValue(value = "languagecookie", required = false) String languagecookie,
			@RequestBody Customer customer) {

		String customeraccount = customer.getCustomeraccount();
		String customername = customer.getCustomername();
		String customeraddress = customer.getCustomeraddress();

		return refundservice.list_refund_customer(opeorgcookie, opetypecookie, customeraccount, customername,
				customeraddress, languagecookie, "总");
	}

	// 列表
	@RequestMapping(value = "/list_refund_customer_child", method = RequestMethod.POST)
	public JsonResult<List<JsonRechargeCustomer>> list_refund_customer_child(
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
			@CookieValue(value = "languagecookie", required = false) String languagecookie,
			@RequestBody Customer customer) {

		String customeraccount = customer.getCustomeraccount();
		String customername = customer.getCustomername();
		String customeraddress = customer.getCustomeraddress();

		return refundservice.list_refund_customer(opeorgcookie, opetypecookie, customeraccount, customername,
				customeraddress, languagecookie, "分");
	}

	// 退费
	@RequestMapping(value = "/refund", method = RequestMethod.POST)
	public JsonResult<Recharge> refund(@RequestBody Recharge recharge,
			@CookieValue(value = "opecodecookie", required = false) String opecodecookie) {

		Integer customerid = recharge.getCustomerid();
		Double money = recharge.getMoney();
		Double lastmoney = recharge.getBeforemoney();

		return refundservice.refund(customerid, opecodecookie, money, lastmoney);

	}

	// 退费历史记录
	@RequestMapping(value = "/refund_history", method = RequestMethod.POST)
	public JsonResult<List<JsonRecharge>> refund_history(@RequestBody Customer customer,
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		Integer customerid = customer.getCustomerid();

		return refundservice.refundhistory(customerid, languagecookie);

	}

}
